﻿using ACC.Business;
using ACC.Business.Stn;
using ACC.Data;
using ACC.Data.Comm;
using ACC.Data.Line;
using ACC.Device;
using ACC.LineDevice.KukaPack;
using System;

namespace Script
{
    /// <summary>
    /// 模组涂活化剂/入箱 （模组入箱）
    /// 进站发托盘号，ACC通过托盘号获取到电箱内部码
    /// 出站发电箱内部码和三个模组码
    /// </summary>
    public class L1P03011 : StnProcessKukaPack
    {
        public L1P03011(StnRunningData data)
            : base(data)
        {
            // Unload 时候PLC发三个模组码，Load时不发
            _data.ProcessUnitIDWhenLoad = false;
        }

        protected override ACCDevice CreateDevice()
        {
            ACCDevice dev = base.CreateDevice();
            if (kukaSiemensDev != null)
            {
                kukaSiemensDev.DB190 = 800;
                kukaSiemensDev.DB190_Offset = 4000;
                kukaSiemensDev.DB192 = 80;
                kukaSiemensDev.DB192_PLC_Offset = 4162; //配方号(PartTypeID)
                kukaSiemensDev.DB192_ACC_Offset = 4200;//工艺参数

                kukaSiemensDev.DB193 = 800;
                kukaSiemensDev.DB193_PLC_Offset = 4034;
                kukaSiemensDev.DB193_ACC_Offset = 4068;
                kukaSiemensDev.DB194 = 800;
                kukaSiemensDev.DB194_PLC_Offset = 4034;
                kukaSiemensDev.DB194_PLC_Data_Offset = 4078;

                kukaSiemensDev.BarcodeLength = 30;
                kukaSiemensDev.LoadBarcodeCount = 1; // 进站发托盘号获取电箱内码
                kukaSiemensDev.UnloadBarcodeCount = 4;

                // TO-DO:
                kukaSiemensDev.Material_COMM_Offset = 164; // 上下料信号位偏移量， 默认68
            }

            return dev;
        }

        public override ACCCode ReadLoadParam(ACCDevice dev, out ACCDevice.LoadParam param)
        {
            kukaSiemensDev.LoadBarcodeCount = 1;
            _data.Components = new BomItemCfg[] { };
            ACCCode rs = base.ReadLoadParam(dev, out param);
            param.ComponentSN = new string[] { };

            return rs;
        }

        public override ACCCode ReadUnloadParam(ACCDevice dev, out ACCDevice.UnloadParam param)
        {
            BomItemCfg itemCfg = _data.PartNo.BomCfg.GetBomItemCfgByIDName("模组").Clone();
            itemCfg.QtyPer = GetBomItemQty("模组");//设定一个模组需要的电芯个数
            _data.Components = new BomItemCfg[] {itemCfg };
            ACCCode rs = base.ReadUnloadParam(dev, out param);
            // TO-DO: _data.LastLoadUnit.UnitSN 为什么?  应该不需要
            //param.UnitSN = _data.LastLoadUnit.UnitSN;

            return rs;
        }
    }
}